<template>
  <a-modal
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-descriptions :title="formInfo.title">
      <a-descriptions-item label="创建时间">{{
        formInfo.createTime
      }}</a-descriptions-item>
      <a-descriptions-item label="维修类型">{{
        formInfo.maintenanceType
      }}</a-descriptions-item>
      <a-descriptions-item label="关联设备">{{
        formInfo.archiveEquipmentId
      }}</a-descriptions-item>
      <a-descriptions-item label="报修人">{{
        formInfo.repairerId
      }}</a-descriptions-item>
      <a-descriptions-item label="报修人手机号">{{
        formInfo.repairerPhone
      }}</a-descriptions-item>
      <a-descriptions-item label="报修位置">{{
        formInfo.repairLocation
      }}</a-descriptions-item>
      <a-descriptions-item label="报修详细位置">{{
        formInfo.repairAddress
      }}</a-descriptions-item>
      <a-descriptions-item label="报修科室">{{
        formInfo.repairDepartmentId
      }}</a-descriptions-item>
      <a-descriptions-item label="故障现象">{{
        formInfo.faultPhenomenon
      }}</a-descriptions-item>
      <a-descriptions-item label="故障说明">{{
        formInfo.faultDescription
      }}</a-descriptions-item>
      <a-descriptions-item label="图片">{{
        formInfo.image
      }}</a-descriptions-item>
      <a-descriptions-item label="紧急度">{{
        formInfo.urgency
      }}</a-descriptions-item>
      <a-descriptions-item label="是否加急">{{
        formInfo.isUrgent
      }}</a-descriptions-item>
      <a-descriptions-item label="工单编号">{{
        formInfo.workOrderNumber
      }}</a-descriptions-item>
      <a-descriptions-item label="工单来源">{{
        formInfo.workOrderSource
      }}</a-descriptions-item>
      <a-descriptions-item label="是否返修">{{
        formInfo.isRepair
      }}</a-descriptions-item>
      <a-descriptions-item label="室内/室外">{{
        formInfo.internalExternalRepair
      }}</a-descriptions-item>
      <a-descriptions-item label="内修负责人">{{
        formInfo.internalMaintenanceManager
      }}</a-descriptions-item>
      <a-descriptions-item label="响应时长">{{
        formInfo.responseTime
      }}</a-descriptions-item>
      <a-descriptions-item label="维修时长">{{
        formInfo.maintenanceDuration
      }}</a-descriptions-item>
      <a-descriptions-item label="维修周期">{{
        formInfo.maintenanceCycle
      }}</a-descriptions-item>
      <a-descriptions-item label="语音描述">{{
        formInfo.phoneticDescription
      }}</a-descriptions-item>
      <a-descriptions-item label="维修方式">{{
        formInfo.maintenanceMethod
      }}</a-descriptions-item>
      <a-descriptions-item label="故障类型">{{
        formInfo.faultType
      }}</a-descriptions-item>
      <a-descriptions-item label="故障原因">{{
        formInfo.reasonMalfunction
      }}</a-descriptions-item>
      <a-descriptions-item label="维修级别">{{
        formInfo.maintenanceLevel
      }}</a-descriptions-item>
      <a-descriptions-item label="预计完修时间">{{
        formInfo.expectedCompletionTime
      }}</a-descriptions-item>
      <a-descriptions-item label="维修描述">{{
        formInfo.repairDescription
      }}</a-descriptions-item>
      <a-descriptions-item label="维修图片">
        <div class="anty-img-wrap">
          <a-avatar
            shape="square"
            :src="getAvatarView(formInfo.repairPictureImage)"
            icon="user"
          />
        </div>
      </a-descriptions-item>
      <a-descriptions-item label="维修厂家">{{
        formInfo.repairManufacturer
      }}</a-descriptions-item>
      <a-descriptions-item label="维修联系人">{{
        formInfo.maintenanceContactPerson
      }}</a-descriptions-item>
      <a-descriptions-item label="维修电话">{{
        formInfo.maintenanceContactPhone
      }}</a-descriptions-item>
      <a-descriptions-item label="预估金额">{{
        formInfo.estimatedAmount
      }}</a-descriptions-item>
      <a-descriptions-item label="预估备注">{{
        formInfo.estimatedRemarks
      }}</a-descriptions-item>
      <a-descriptions-item label="预估附件">{{
        formInfo.estimatedFile
      }}</a-descriptions-item>
      <a-descriptions-item label="预估图片">{{
        formInfo.estimatedImage
      }}</a-descriptions-item>
      <a-descriptions-item label="实际费用合计金额">{{
        formInfo.amountTotal
      }}</a-descriptions-item>
    </a-descriptions>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'
import { getAction } from '@/api/manage'

export default {
  name: 'DevMaintenanceView',
  components: {},
  data() {
    return {
      visible: false,
      confirmLoading: false,
      formInfo: {},
      url: {
        saveInfo: '/system/devMaintenance/save',
        getInfo: '/system/devMaintenance/info',
      },
    }
  },
  created() {},
  methods: {
    show(record) {
      this.formInfo = Object.assign({}, record)
      if (this.formInfo.id) {
        getAction(this.url.getInfo, { id: record.id }).then((res) => {
          this.$nextTick(() => {
            this.formInfo = pick(
              res.result.data,
              'id',
              'createTime',
              'maintenanceType',
              'archiveEquipmentId',
              'repairerId',
              'repairerPhone',
              'repairLocation',
              'repairAddress',
              'repairDepartmentId',
              'faultPhenomenon',
              'faultDescription',
              'image',
              'urgency',
              'isUrgent',
              'workOrderNumber',
              'workOrderSource',
              'isRepair',
              'internalExternalRepair',
              'internalMaintenanceManager',
              'responseTime',
              'maintenanceDuration',
              'maintenanceCycle',
              'phoneticDescription',
              'maintenanceMethod',
              'faultType',
              'reasonMalfunction',
              'maintenanceLevel',
              'expectedCompletionTime',
              'repairDescription',
              'repairPictureImage',
              'repairManufacturer',
              'maintenanceContactPerson',
              'maintenanceContactPhone',
              'estimatedAmount',
              'estimatedRemarks',
              'estimatedFile',
              'estimatedImage',
              'amountTotal'
            )
          })
        })
      }
      this.visible = true
    },
    // 图像处理
    getAvatarView: function (avatar) {
      return this.$getFileAccessHttpUrl(avatar)
    },
    // 确定
    handleSubmit() {
      this.visible = false
    },
    // 关闭
    handleCancel() {
      this.close()
    },
    close() {
      this.visible = false
    },
  },
}
</script>
